// theme.js ??????????
//han_feng 2003.11

//????????
var	_INCLUDE_THEME_JS = "YES";

//????????????
if( typeof(CONTEXT_ROOT) == "undefined"  ) CONTEXT_ROOT = "/";
if( typeof(COOKIES_JS_PATH) == "undefined" ) COOKIES_JS_PATH = "js/cookies.js";

//?? cookies.js ????
//???????????? cookies.js
if( typeof(_INCLUDE_COOKIES_JS) == "undefined" || _INCLUDE_COOKIES_JS != "YES" )
	document.write("<SCRIPT LANGUAGE=\"JavaScript\" src=\""+ CONTEXT_ROOT + COOKIES_JS_PATH +"\"></SCRIPT>");

/////////////////////////////////////////////
// Theme ????????
// han_feng 2003.11
function Theme() {
	this.folder = "theme";
	this.defaultTheme = "def";
	this.defaultMod = "public";
	this.themes = [];
	this.mods = [];

	this.mods["menu"] = "OK";
	this.mods["login"] = "OK";
	this.mods["top"] = "OK";
	this.mods["dialogbox"] = "OK";
	this.mods["tabpane"] = "OK";

	this.themes["winxp"] = "OK";
	this.themes["large"] = "OK";
	this.themes["webfx"] = "OK";

	this.theme = null;
	this.mod = null;
}

Theme.prototype.checkMod = function( modName ) {
	return ( this.mods[ modName ]!=null && this.mods[ modName ]=="OK")
}

Theme.prototype.checkTheme = function( themeName ) {
	return ( this.themes[ themeName ]!=null && this.themes[ themeName ]=="OK")
}

Theme.prototype.getCommonCssFile = function() {
	var commonCssFile = CONTEXT_ROOT
			+ this.folder + "/common.css";
	return commonCssFile;
}

Theme.prototype.getCssFile = function() {
	var cssFile = CONTEXT_ROOT
			+ this.folder + "/"
			+ this.theme + "/"
			+ this.mod + ".css";
	//alert("cssfile="+cssFile);
	return cssFile;
}

Theme.prototype.getDefCssFile = function() {
	var cssFile = CONTEXT_ROOT
			+ this.folder + "/"
			+ this.defaultTheme + "/"
			+ this.mod + ".css";
	//alert("deffile="+cssFile);
	return cssFile;
}
Theme.prototype.getTopCssFile = function() {
	var cssFile = CONTEXT_ROOT
			+ this.folder + "/"
			+ this.theme + "/top.css"
	//alert("topcssfile="+cssFile);
	return cssFile;
}
Theme.prototype.init = function() {
	var t = getCookie( "CMIS_themeSetting" );
	if( t==null || !this.checkTheme(t) ){
		if( this.checkTheme(this.theme) ) t = this.theme;
		else t = this.defaultTheme;
	}
	this.theme = t;
	if( !this.checkMod( this.mod ) ) this.mod = this.defaultMod;

	document.writeln( "<LINK href=\""
						+ this.getCommonCssFile()
						+ "\" rel=\"stylesheet\" type=\"text/css\">" );
	document.writeln( "<LINK href=\""
						+ this.getCssFile()
						+ "\" rel=\"stylesheet\" type=\"text/css\">" );
	document.writeln( "<LINK href=\""
						+ this.getTopCssFile()
						+ "\" rel=\"stylesheet\" type=\"text/css\">" );
	this.save();
}

Theme.prototype.change = function( newTheme ) {
	if( this.checkTheme( newTheme) ) {
		this.theme = newTheme;
	}
	else this.theme = this.defaultTheme;
}

Theme.prototype.save = function() {
	setCookie("CMIS_themeSetting" , this.theme, 30 );
}

//????????
var myTheme = new Theme();

if( typeof(myThemeMod) == "undefined" ) myThemeMod = myTheme.defaultMod;
myTheme.mod = myThemeMod;

myTheme.init();
